//
//  XHCollectViewModel.m
//  xinhua_sx
//
//  Created by 党阳阳 on 14-5-29.
//  Copyright (c) 2014年 dangyangyang. All rights reserved.
//

#import "XHCollectViewModel.h"

@interface XHCollectViewModel()
@property (nonatomic ,strong) NSString *URLString;

@end

@implementation XHCollectViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
       
        
       
        
    }
    return self;
}
- (RACSignal *)getCollectItemWithCurrentPage:(NSInteger)currentPage pageSize:(NSInteger)pageSize
{
    
    return  [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
        id uid = [defaults objectForKey:@"UID"];
        
        if (!uid) {
           
            [subscriber sendNext:@"尚未登录"];
            
            
        }else{
            NSString *currentPageString = [NSString stringWithFormat:@"%ld",(long)currentPage];
            NSString *pageSizeString = [NSString stringWithFormat:@"%ld",(long)pageSize];
            NSString *uidString = [NSString stringWithFormat:@"%@",uid];
            NSString* string = [NSString stringWithFormat:@"http://183.203.18.45:7001//xinhua/m/articleListfindByUserId-%@.html?pageNo=%@&pageSize=10",uid,currentPageString];
            NSLog(@"我的收藏 =%@",string);
            
            NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:string]];
            [urlRequest setHTTPMethod:@"GET"];
            [urlRequest setTimeoutInterval:10];
            
            NSOperationQueue *queue= [[NSOperationQueue alloc] init];
            
            [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                
                if ([data length]>0 && connectionError == nil){
                    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&connectionError];
                    
                    [subscriber sendNext:dic];
                 }
                
                
            }];
            

        
        }
        
        return nil;
        
    }];
}
@end
